/**
 * commonData.js
 * 公共服务方法appService服务方法
 */

var appservice = { 
  /**
   * 获取买方信息
   */
  getBuyerInfo: function(callback) {
    //假数据
    this.refreshBuyerInfo({
      CstName: "磊哥哥",
      CstGUID: "25945C0D-F1C9-E711-825B-001C429EBBDE"
    });

    wx.getStorage({
      key: 'CstInfo',
      success: callback,
    })
  },
  /**
   * 刷新买方信息
   */
  refreshBuyerInfo: function(cstInfo) {
    wx.setStorage({
      key: 'CstInfo',
      data: cstInfo,
    })
  },

  appHead: function() {
    return {
      header: {
        AppId: getApp().ServiceData.AppId,
        AppKey: getApp().ServiceData.AppKey,
        openId: getApp().ServiceData.openId,
        //Host: getApp().ServiceData.HostServiceIp,
        "Content-Type": "application/json"
      },     
    }
  },

  /**
   * post请求头
   */
  appPostHead: function() {
    var obj = this.appHead();
    obj.method = "post";
    return obj;
  },
  /**
   * get请求头
   */
  appGetHead: function() {
    var obj = this.appHead();
    obj.method = "get";
    return obj;
  },

  /**
   * 请求主机头信息
   */
  appRequestHeadData: function(methodType, methodName) {
    var data = methodType == 1 ? this.appPostHead() : this.appGetHead();
    data.url = "http://" + getApp().ServiceData.HostServiceIp + "/" + getApp().ServiceData.serviceName + "/" + methodName; 
    return data;
  }  
}

module.exports = appservice;